<template>
  <el-container class="container">
    <el-header class="head">
      <svg class="icon">
        <use xlink:href="#icon-kuaican"></use>
      </svg>
      <div>
        <div class="head-right">
          <svg class="icon">
            <use xlink:href="#icon-lingsheng-copy"></use>
          </svg>
          <!-- <svg class="icon">
            <use xlink:href="#icon-touxiang-"></use>
          </svg> -->
          <div style="position: relative;">
            <el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
            <ul class="list">
              <li v-for="item in list" :key="item.id">
                <div>
                  <svg class="icon">
                    <!-- : xlink: href单向绑定，前面加个冒号 -->
                    <use :xlink:href="item.icon"></use>
                  </svg>
                  <span style="vertical-align:top; ">{{ item.title }}</span>
                </div>
                <svg class="icon">
                  <use xlink:href="#icon-jiantou"></use>
                </svg>

              </li>
            </ul>
          </div>
          <svg class="icon" @click="router.replace('/login')">
            <use xlink:href="#icon-Union-32"></use>
          </svg>

        </div>
      </div>
    </el-header>

    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px" class="aside">
        <!-- 减号要用空格隔开 -->
        <el-scrollbar style="height: calc(100vh - 60px); ">
          
          <el-menu router unique-opened default-active="/control/product">
            <div v-for="item in menu" :key="item.id">
              <template v-if="item.children">
                <el-sub-menu :index="item.id" >
                  <template #title>
                    <svg style="width: 20px;height: 20px;padding: 0 20px;">
                      <use :xlink:href="item.icon"></use>
                    </svg>
                    <span>{{ item.title }}</span>
                  </template>
                  <el-menu-item-group>
                    <el-menu-item v-for="p in item.children" :key="p.id" :index="p.path">
                      {{ p.title }}
                    </el-menu-item>
                  </el-menu-item-group>
                </el-sub-menu>
              </template>
              <template v-else>
                <el-menu-item :index="item.path">
                  <svg style="width: 20px;height: 20px;padding: 0 20px;">
                    <use :xlink:href="item.icon"></use>
                  </svg>
                  <span>{{ item.title }}</span>
                </el-menu-item>
              </template>
            </div>
          </el-menu>
        </el-scrollbar>
      </el-aside>
      <el-main class="main">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>

import { ref } from 'vue'
import { useRouter } from 'vue-router';

const list = ref([
  { id: 1, path: '', icon: '#icon-icon03-copy', title: '个人中心' },
  { id: 2, path: '', icon: '#icon-icon_xinyong_xianxing_jijin-133', title: '个人空间' },
  { id: 3, path: '', icon: '#icon-shoudongicon', title: '账户设置' },
])

const menu = ref([
  {
    id: 1, icon: '#icon-shangpinguanli', title: '商品管理', children: [
      { pid: 1, id: 11, path: '/control/product', title: '菜品详情' },
      { pid: 1, id: 12, path: '/control/product1', title: '套餐详情' },
    ]
  },
  {
    id: 2, icon: '#icon-yonghuguanli', title: '用户订单管理', children: [
      { pid: 2, id: 21, path: '/control/order', title: '订单信息' },
    ]
  },
])
// const menu = ref([
//   {
//     id: 1, icon: '#icon-shangpinguanli', title: '商品管理', children: [
//       { pid: 1, id: 11, path: '/control/product', title: '菜品详情' },
//       { pid: 1, id: 12, path: '/control/product1', title: '套餐详情' },
//     ]
//   },
//   {
//     id: 2, icon: '#icon-yonghuguanli', title: '用户订单管理', children: [
//       { pid: 2, id: 21, path: '/control/order', title: '订单信息' },
//       { pid: 2, id: 22, path: '/control/ordercase', title: '订单明细' },
//     ]
//   },
//   { id: 3, path: '', icon: '#icon-huodongguanli', title: '活动管理' },
// ])

// const menu = ref([
//   {
//     id:1,icon:'',title:'登录界面',path:''
//   },
//   {
//     id:2,icon:'',title:'注册界面',path:''
//   },
//   {
//     id:3,icon:'',title:'首页',path:''
//   },
//   {
//     id:4,icon:'',title:'搜索页面',path:''
//   },
//   {
//     id:5,icon:'',title:'菜单页面',path:'',children:[
//     { pid: 5, id: 51, path: '', title: '套餐详情' },
//     { pid: 5, id: 52, path: '', title: '菜品详情' },
//     ]
//   },
//   {
//     id:6,icon:'',title:'购物车页面',path:''
//   },
//   {
//     id:7,icon:'',title:'我的页面',path:'',children:[
//     { pid: 7, id: 71, path: '', title: '个人信息' },
//     { pid: 7, id: 72, path: '', title: '个人地址' },
//     { pid: 7, id: 73, path: '', title: '订单页面' },
//     { pid: 7, id: 74, path: '', title: '订单明细页面' },
//     ]
//   }
// ])
const router = useRouter()
</script>

<style scoped>
.container {
  height: 100vh;
}

.head {
  background-color: skyblue;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.icon {
  width: 40px;
  height: 40px;
  padding-left: 40px;
}

.aside {
  background-color: azure;
}

.head-right {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 200px;
}

.head-right .icon {
  padding: 0;
  width: 30px;
  height: 30px;
}

.head-right>div:hover .list {
  display: block;
}

.list {
  position: absolute;
  width: 300px;
  padding: 10px 20px;
  top: 50px;
  right: -80px;
  box-shadow: rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px;
  display: none;
}


.list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding: 10px 0;
}

.list div .icon {
  width: 20px;
  height: 20px;
  padding: 0 20px;
}
</style>